package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.InfoUpload;
import com.ruoyi.system.service.IInfoUploadService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 信息上传Controller
 *
 * @author ruoyi
 * @date 2024-05-01
 */
@RestController
@RequestMapping("/system/upload")
public class InfoUploadController extends BaseController {
    @Autowired
    private IInfoUploadService infoUploadService;

    /**
     * 查询信息上传列表
     */
    @PreAuthorize("@ss.hasPermi('system:upload:list')")
    @GetMapping("/list")
    public TableDataInfo list(InfoUpload infoUpload) {
        startPage();
        List<InfoUpload> list = infoUploadService.selectInfoUploadList(infoUpload);
        return getDataTable(list);
    }

    /**
     * 导出信息上传列表
     */
    @PreAuthorize("@ss.hasPermi('system:upload:export')")
    @Log(title = "信息上传", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, InfoUpload infoUpload) {
        List<InfoUpload> list = infoUploadService.selectInfoUploadList(infoUpload);
        ExcelUtil<InfoUpload> util = new ExcelUtil<InfoUpload>(InfoUpload.class);
        util.exportExcel(response, list, "信息上传数据");
    }

    /**
     * 获取信息上传详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:upload:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(infoUploadService.selectInfoUploadById(id));
    }

    /**
     * 新增信息上传
     */
    @PreAuthorize("@ss.hasPermi('system:upload:add')")
    @Log(title = "信息上传", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody InfoUpload infoUpload) {
        return toAjax(infoUploadService.insertInfoUpload(infoUpload));
    }

    /**
     * 检测
     */
    @PreAuthorize("@ss.hasPermi('system:upload:add')")
    @PostMapping("/detection")
    public AjaxResult detection(@RequestBody InfoUpload infoUpload) {
        return AjaxResult.success();
    }

    /**
     * 修改信息上传
     */
    @PreAuthorize("@ss.hasPermi('system:upload:edit')")
    @Log(title = "信息上传", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody InfoUpload infoUpload)
    {
        return toAjax(infoUploadService.updateInfoUpload(infoUpload));
    }

    /**
     * 删除信息上传
     */
    @PreAuthorize("@ss.hasPermi('system:upload:remove')")
    @Log(title = "信息上传", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(infoUploadService.deleteInfoUploadByIds(ids));
    }
}
